﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bystd.Geo.GeoParsers
{
    public class BaseFile : IBase
    {
        protected string PathName;
        protected Encoding encoding = Encoding.UTF8;
        private FileStream fs = null;
        private BinaryReader binReader = null;
        private StreamReader strReader = null;

        public BaseFile(string pathName)
        {
            this.PathName = pathName;
        }

        public BaseFile(string pathName, Encoding encoding)
            :this(pathName)
        {
            this.encoding = encoding;
        }

        public BinaryReader BinReaderStream()
        {
            fs = File.OpenRead(PathName);
            binReader = new BinaryReader(fs, encoding);
            return binReader;
        }

        public StreamReader StrReaderStream()
        {
            fs = File.OpenRead(PathName);
            strReader = new StreamReader(fs, encoding);
            return strReader;
        }

        public virtual void Dispose()
        {
            if (binReader != null)
                binReader.Dispose();

            if (strReader != null)
                strReader.Dispose();

            if (fs != null)
                fs.Dispose();
        }
    }
}
